<template>
	<view class="content">
		<view class="loading">
			<view class="logo">

			</view>
			<view class="loading-box">
				<view class="line">

				</view>
			</view>
			<text class="jiazai">加载中··· ···</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		onLoad() {
			this.getUserInfoRes()
		},
		methods: {
			getUserInfoRes() {
				uni.showLoading({
					title: '正在加载数据',
					mask: true
				})
				var ua = navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == "micromessenger") {
					let code = GetQueryString("code")
					console.log('code', code); //哪这个code去服务端换userInfo
					this.code = code
					uniCloud.callFunction({
						name: 'getUserInfo',
						data: {
							code: this.code
						}
					}).then((res) => {
						console.log('getUserInfo', res)
						let userInfo = res.result.data
						// uni.setStorageSync('userInfo',res.result.data)
						uniCloud.callFunction({
							name: 'saveUser',
							data: userInfo
						}).then((res1) => {
							console.log('res1', res1)
							uni.hideLoading()

							uni.setStorageSync('userInfo', res1.result.data[0])
							uni.setStorageSync('openid', res1.result.data[0].openid)

							uni.redirectTo({
								url: '../choose/choose'
							})


						})
					}).catch((res) => {
						uni.hideLoading()
						console.log(res)

					})
				} else {
					uni.hideLoading()
					console.log('不在微信里面不能微信登录');
					return false

					// return false;
				}

				function GetQueryString(name) //获取参数
				{
					var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
					var r = window.location.search.substr(1).match(reg); //search,查询？后面的参数，并匹配正则
					if (r != null) return unescape(r[2]);
					return null;
				}
			},

		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #d2d2d2;
		height: 100%;
	}

	.loading {
		width: 100%;
		height: 100%;
		background: url('@/static/kuang.png') no-repeat center center;
		background-size: 100% 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		// margin-top: 136rpx;
	}

	.logo {
		width: 666rpx;
		height: 46rpx;
		background: url('@/static/logo.png') no-repeat center center;
		background-size: 100% 100%;
		margin-top: 60rpx;
	}

	.loading-box {
		width: 386rpx;
		height: 46rpx;
		border-radius: 23rpx;
		overflow: hidden;
		margin-top: 530rpx;
		border: 1px solid #777777;

		.line {
			height: 100%;
			background: linear-gradient(90deg, #046ff9, #dd0419);
			animation: donghua 2s linear infinite;
			border-radius: 23rpx;
			border: 1px solid #898989;
		}
	}

	.jiazai {
		font-size: 32rpx;
		color: #dd1914;
		font-weight: bold;
		word-spacing: 2px;
		letter-spacing: 2px;
		margin-top: 54rpx;
	}

	@keyframes donghua {
		0% {
			width: 0%;
		}

		50% {
			width: 50%;
		}

		100% {
			width: 100%;
		}
	}
</style>
